
<?
/*
 * trips.php
 * serves up trip info from the database
 * if given no params it shows regions as defined by the `regions` table
 * if passed 'region' param it shows info for all trips in specified region with short descriptions
 * if passed 'grade' param it shows info for all trips at that grade level.
 * if passed 'tripid' param it shows trip info with full description.
 * 
 * Written By: Brian Thorne
 * Last Updated: 1/4/08
 */

include('data/class.trip.php');
$content = '';
$content .= '<h2>White Water Kayaking Trips</h2><br /><h3>This is a work in progress, eventually you will be able to upload your own trip info and pictures here. Any questions or to encourage me to keep working on it, email me hardbyte@gmail.com </h3>';

    /** do this fist so we can redirect if necessary without outputting code...
      * add a post to tripdb
     **/
if (isset($_POST['post']) && $_SESSION['logged'])
{
    $trip->addPost($_POST['tripid'],$session->username,$_POST['post']);
    http_redirect("trips.inc.php", array("tripid" => $_POST['tripid']), false, HTTP_REDIRECT_PERM);
}

/*
* Add a new trip into the database.
*/
if ($_POST['newtrip']) 
{
    extract($_POST);
    $trip->newTrip($name, $short_d, $long_d, $region, $map,$photos,$time, $grade);
}

if (isset($_GET['region']))
{
    //display regional trips
    $output = $trip->fetchByRegionId($_GET['region']);
    if($_SESSION['logged'] && $_SESSION['rights'] & $r_comittee) $output .= $trip->fetchAddTrip(); 
    if ($output)
	{
        $content .= $output;
    } else 
	{
        $content .= "No data in Database";
    }
    
} elseif (isset($_GET['grade']))
{
    //display trips by grade
    $output = $trip->fetchByGrade($_GET['grade']);
    if ($output)
	{
        $content .= $output;
    } else 
	{
        $content .= "No data in Database";
    }
    
}elseif (isset($_GET['tripid']))
{
    /**
      * display trip info (single)    
      * */
    $output = $trip->fetchByTripId($_GET['tripid']);
    if ($output){
        $content .= $output;
        $content .= $trip->fetchPostData($_GET['tripid']);
        $content .= $trip->getPostBox($_GET['tripid']);
    } else {
        $content .= "No data in Database.. yet!";
    }   
    
} else {
    //display regions
    $output = $trip->fetchRegions();
    if ($output)
	{
		//display regions
        $content .= "<h1>Select a region:</h1>";
        $content .= $output;
    } else {
        echo "No data in Database.... yet";
    }
}



?>
